package com.yiyang.controller;

import com.yiyang.constant.ResultCode;
import com.yiyang.domain.Result;
import com.yiyang.domain.ResultPage;
import com.yiyang.domain.po.NurseContent;
import com.yiyang.service.NurseContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/nursecontent")
public class NurseContentController {

    @Autowired
    private NurseContentService nurseContentService;

    @GetMapping("/findNurseItemPage")
    public Result<ResultPage<NurseContent>> findNurseItemPage(@RequestParam(defaultValue = "1") Integer page,
                                                              @RequestParam(defaultValue = "5") Integer pageSize,
                                                              String itemName,
                                                              Integer levelId,
                                                              Integer status){
        ResultPage<NurseContent> resultPage = nurseContentService.findNurseItemPage(page,pageSize,itemName,levelId,status);

        return Result.success(resultPage);
    }

    @PostMapping("/addNurseItem")
    public Result addNurseItem(@RequestBody NurseContent nurseContent){
        nurseContent.setIsDeleted(0);

        boolean flag = nurseContentService.save(nurseContent);

       if(flag){
           return Result.success();
       }else{
           return Result.fail(ResultCode.NURSECONTENT_ADD,"新增护理项目失败");
       }
    }

    @PutMapping("/updateNurseItem")
    public Result updateNurseItem(@RequestBody NurseContent nurseContent){
        nurseContentService.updateNurseItem(nurseContent);
        return Result.success();
    }

    @DeleteMapping("/delNurseItem")
    public Result delNurseItem(Integer id){
        nurseContentService.delNurseItem(id);
        return Result.success();
    }
}
